# Name: [Send Email From Forum]
# By: [Wyatt Preul]
# This will test navigating to a forum post and sending an email
# Maintenance:
#   [10/10/2006] : [WLP] : Created
#

require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
#require '../resources/class.emails.rb'
require '../resources/functions.rb'


class TC_SendEmailFromForum_test < Test::Unit::TestCase
    
    def startup
      @@ie = Watir::IE.start($SITE_URL)
    end
    
    def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
    end
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))	
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end    
    
    def test_06_navigateToForum
      assert_equal $SITE_URL +'forums/', ie.link(:text, 'Forums').href
      ie.link(:text, 'Forums').click
      assert(ie.link(:text, /Sample Forum$/).exists?)
      ie.link(:text, /Sample Forum$/).click
    end
    
    def test_07_navigateToForumPost
      assert(ie.link(:text, "post test").exists?)
      ie.link(:text, "post test").click
      assert(ie.contains_text("post test"))
    end
    
    def test_08_verifyForumButtonsExist
      assert(ie.link(:text, "Reply").exists?)
      assert(ie.link(:text, "Delete").exists?)
      assert(ie.link(:text, "Edit").exists?)
      assert(ie.link(:text, "Favorites").exists?)
      assert(ie.link(:text, "Contact").exists?)
      assert(ie.link(:text, "Moderate").exists?)
      assert(ie.link(:text, "Previous").exists?)
      assert(ie.link(:text, "Next").exists?)
      assert(ie.link(:text, "Reply").exists?)
      assert(ie.link(:text, "Change View").exists?)\
    end
    
    def test_09_clickSendEmail
      ie.link(:text, "Contact").click
      
      sleep 5 
      assert(ie.cell(:id, 'item0').exists?)
      ie.cell(:id, 'item0').click
      
      sleep 5
      
      assert(ie.frame(:index, 1).button(:id, /SendButton$/).exists?)
      assert(ie.frame(:index, 1).text_field(:id, /Subject$/).exists?)
      
      
      ie.frame(:index, 1).text_field(:id, /Subject$/).value = 'test'
      
      ie.frame(:index, 1).button(:id, /SendButton$/).click
    end
    
    def test_10_checkOutGoingEmail
      sleep 20
      emails = Emails.new
      assert(emails.isEmailValid?($ADMIN_EMAIL, "SendEmail"))
    end
    
end